package com.newcapec.shuttle.manager.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.newcapec.shuttle.manager.entity.ElcInfotype;
import com.newcapec.shuttle.manager.entity.ElcRoleInfotype;
import com.newcapec.shuttle.manager.entity.IdEmpVO;
import com.newcapec.shuttle.manager.mapper.ElcRoleInfotypeMapper;
import com.newcapec.shuttle.manager.service.IElcRoleInfotypeService;

import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author fujun
 * @since 2020-11-15
 */
@Service
public class ElcRoleInfotypeServiceImpl extends ServiceImpl<ElcRoleInfotypeMapper, ElcRoleInfotype> implements IElcRoleInfotypeService {

    @Resource
    private  ElcRoleInfotypeMapper elcRoleInfotypeMapper;

    @Override
    public IPage<IdEmpVO> queryAllEmp(IPage<IdEmpVO> page, Map<String, Object> params) {
        return elcRoleInfotypeMapper.queryAllEmp(page, params);
    }

    @Override
    public void saveRole(Integer userid, Integer[] infoTypeIds) {
           elcRoleInfotypeMapper.delete(new QueryWrapper<ElcRoleInfotype>().eq("user_id",userid));
           List<ElcRoleInfotype> list=new ArrayList<>();
           for (Integer infoid:infoTypeIds){
            list.add(new ElcRoleInfotype(userid,infoid));
           }
           this.saveBatch(list);
    }

    @Override
    public List<ElcInfotype> queryInfoTypeByUserId(Integer id) {
        return elcRoleInfotypeMapper.queryInfoTypeByUserId(id);
    }


}